package com.eternalrights.mapper;

import com.eternalrights.pojo.Emp;
import com.eternalrights.pojo.EmpQueryResult;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
//    @Select("SELECT COUNT(*) FROM emp e LEFT OUTER JOIN dept d ON e.dept_id = d.id")
//    public long count();
//
//    @Select("SELECT e.*,d.name AS deptname FROM emp e LEFT JOIN dept d ON e.dept_id = d.id " +
//            "ORDER BY e.update_time DESC LIMIT #{start},#{pageSize}")
//    public List<Emp> list(Integer start,Integer pageSize);
//    @Select("SELECT e.*,d.name AS deptname FROM emp e LEFT JOIN dept d ON e.dept_id = d.id ORDER BY e.update_time DESC")
    public List<Emp> list(EmpQueryResult empQueryResult);

    @Options(useGeneratedKeys = true,keyProperty="id")
    @Insert("INSERT INTO emp (username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) VALUES" +
            "(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    public void insert(Emp emp);

    public void deleteByIds(List<Integer> ids);

    public Emp getById(Integer id);

    public void updateById(Emp emp);

    @MapKey("pos")
    public List<Map<String,Object>> countEmpJobData();

    @MapKey("pos")
    public List<Map<String,Object>> countEmpGenderData();

    @Select("SELECT * FROM emp")
    public List<Emp> findEmp();

    @Select("SELECT COUNT(*) FROM emp WHERE dept_id = #{deptId}")
    public Integer countByDeptId(Integer deptId);

    @Select("SELECT id,username,password FROM emp WHERE username = #{username} AND password = #{password}")
    public Emp selectByUsernameAndPassword(Emp emp);
}
